package com.pls.servlets;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.pls.actionAdapter.PlsAdapter;
import com.pls.javabeans.GetSeatCodesByFloorBean;
import com.pls.javabeans.GetSeatMapByFloorBean;
import com.pls.javabeans.GetSeatMapByQuadrantBean;

/**
 * Servlet implementation class ViewSeatMapServlet
 */
@WebServlet("/ViewSeatMapServlet")
public class ViewSeatMapServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * Default constructor.
	 */
	public ViewSeatMapServlet() {
		// TODO Auto-generated constructor stub
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		process(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

	protected void process(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {

		String location = request.getParameter("location");

		PlsAdapter adapter = new PlsAdapter();

		try {

			GetSeatMapByFloorBean seatMapByFloor = new GetSeatMapByFloorBean();
			GetSeatMapByQuadrantBean seatMapByQuadrant = new GetSeatMapByQuadrantBean();
			GetSeatCodesByFloorBean seatcodeByFloor = new GetSeatCodesByFloorBean();

			seatMapByFloor = adapter.getSeatMapFloor(location, "");
			seatMapByQuadrant = adapter.getSeatMapByQuadrant(location, "");
			seatcodeByFloor = adapter.getCodesByFloor(location, "");

			request.setAttribute("seatMapByQuadrant",
					seatMapByQuadrant.getLocationSeatMap());
			request.setAttribute("seatCode",
					seatcodeByFloor.getLocationSeatMap());
			request.setAttribute("floorSeatMap",
					seatMapByFloor.getLocationSeatMap());

			// Do an if else here, directing to other

			if (location == "PIC3FC") {

				RequestDispatcher goToquadrantc = request
						.getRequestDispatcher("pages/seatmap3fc.jsp");
				goToquadrantc.forward(request, response);
			} else if (location == "PIC3FB") {

				RequestDispatcher goToquadrantb = request
						.getRequestDispatcher("pages/seatmap3fb.jsp");
				goToquadrantb.forward(request, response);
			}

			RequestDispatcher goToquadrantA = request
					.getRequestDispatcher("pages/seatmap3fa.jsp");
			goToquadrantA.forward(request, response);

		}

		catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
